package com.mingtu.dzpatrol.base;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import com.blankj.utilcode.util.AdaptScreenUtils;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.SPStaticUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.gyf.immersionbar.ImmersionBar;
import com.lzy.okgo.OkGo;
import com.mingtu.dzpatrol.R;
import com.mingtu.dzpatrol.activity.LoginActivity;
import com.mingtu.dzpatrol.api.AppConfig;
import com.mingtu.dzpatrol.broadcast.NetBroadcastReceiver;
import com.mingtu.dzpatrol.manager.ScreenManager;
import com.mingtu.dzpatrol.utils.ActivityUtil;
import com.mingtu.dzpatrol.utils.Constant;
import com.mingtu.dzpatrol.utils.DialogUtils;
import com.mingtu.dzpatrol.utils.IntentUtils;
import com.mingtu.dzpatrol.utils.MyLogUtil;
import com.mingtu.dzpatrol.utils.SPTools;
import com.mingtu.dzpatrol.utils.ScreenUtils;
import com.mingtu.dzpatrol.view.LoadingDialog;
import com.mingtu.dzpatrol.view.MyDialog;
import com.mingtu.dzpatrol.view.ProgressBarLayout;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.xuexiang.xupdate.XUpdate;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @ClassName :BaseActivity是所有Activity的基类，把一些公共的方法放到里面，如基础样式设置，权限封装，网络状态监听等
 * @Author : wkk
 * @Date : 2020/4/24 15:37:12
 * @Email : 1281573890@qq.com
 * @Eescription :
 */
public abstract class BaseActivity extends AppCompatActivity implements NetBroadcastReceiver.NetChangeListener, View.OnClickListener, NetworkUtils.OnNetworkStatusChangedListener {
    //    public static NetBroadcastReceiver.NetChangeListener netEvent;// 网络状态改变监听事件
    private ScreenManager screenManager;
    protected boolean isStatusBar = false;//是否沉浸状态栏
    protected boolean isFullScreen = false;//是否允许全屏
    protected boolean isScreenPortrait = true;//是否禁止旋转屏幕
    private Dialog mProgressDialog;//不可取消框
    private Dialog mProgressDialogCancle;//可取消加载框
    public Context context;
    private Unbinder unbinder;
    private int titlebarResId = R.layout.top_titlebar_base;
    private RelativeLayout mRelLayoutBase;
    private FrameLayout mFraLayoutContent;
    private FrameLayout mFraLayoutHeadView;
    private ProgressBarLayout mLoadingBar;
    private RelativeLayout errorLayout;
    private RelativeLayout emptyLayout;
    private TextView mResetButton;
    private ImageView topLeftButton;
    private ImageView topRightImg;
    private TextView tvEmtyHit;
    private RelativeLayout relTitleBar;
    private TextView moduleTextView;
    private ImageView topRightShare;
    public LinearLayout clTitlebar;
    private TextView rightText;
    private NetBroadcastReceiver networkChangeReceiver;
    private LinearLayout layoutTop;
    private MyDialog myDialog = null;
    private View statusBarView;
    private LoadingDialog mLoadingDialog;
    public ProgressBar topProgressBar;
    private String password;
    public boolean netWorkState = NetworkUtils.isConnected();
    private SmartRefreshLayout baseSrlUp;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        unbinder = ButterKnife.bind(this);
        context = BaseApplication.getContext();
        // 隐藏标题栏
        if (getSupportActionBar() != null) getSupportActionBar().hide();
        screenManager = ScreenManager.getInstance();
        screenManager.setStatusBar(isStatusBar, this);
//        screenManager.setScreenRoate(isScreenPortrait, this);
        screenManager.setFullScreen(isFullScreen, this);
        ScreenUtils.setPortrait(this);
        // 添加到Activity工具类
        ActivityUtil.getInstance().addActivity(this);
        // 执行初始化方法
        showTopLeftButton();
        initMap(savedInstanceState);
        initView();
        initData();
        getData();

        checkUpdate();

        //网络状态监听
        NetworkUtils.registerNetworkStatusChangedListener(this);

        //网络状态监听,动态注册方式的BroadcastReceiver，生命周期仅限于当前注册的activity,静态注册的BroadcastReceiver，生命周期不仅局限于activity
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
        networkChangeReceiver = new NetBroadcastReceiver();
        registerReceiver(networkChangeReceiver, intentFilter);
        networkChangeReceiver.setNetChangeListener(this);
//        netEvent = this;
    }

    @Override
    protected void onStart() {
        MyLogUtil.e("offline", "BaseActivity onStart==");
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
        MyLogUtil.e("offline", "BaseActivity onResume==");
        Resources resources = this.getResources();
        Configuration configuration = resources.getConfiguration();
        configuration.fontScale = 1;
        resources.updateConfiguration(configuration, resources.getDisplayMetrics());//字体的大小
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        // Activity销毁时，提示系统回收
        // System.gc();
        ActivityUtil.getInstance().removeActivity(this);     // 移除Activity
        unbinder.unbind();//ButterKnife 解绑
        OkGo.getInstance().cancelTag(this);//Activity销毁时，取消网络请求
        unregisterReceiver();
        NetworkUtils.unregisterNetworkStatusChangedListener(this);
        //防止界面处于横屏退出时，再次进入出现布局显示问题
        if (ScreenUtils.isLandscape()) {
            ScreenUtils.setPortrait(this);
        }
        super.onDestroy();
    }

    @Override
    public void onConfigurationChanged(@NonNull Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        // 点击手机上的返回键，返回上一层
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            onKeyDownEvnet();
            // 移除Activity
            ActivityUtil.getInstance().removeActivity(this);
        }
        return super.onKeyDown(keyCode, event);
    }

    //onDisconnected 、onConnected 有时候会不准，禁用
    @Override
    public void onDisconnected() {
        MyLogUtil.e("NetworkUtils", getClass().getSimpleName() + ",onDisconnected====");
    }

    @Override
    public void onConnected(NetworkUtils.NetworkType networkType) {
        MyLogUtil.e("NetworkUtils", getClass().getSimpleName() + ",onConnected====");

    }

    /**
     * 网络状态改变时间监听
     *
     * @param netWorkState true有网络，false无网络
     */
    @Override
    public void onNetChange(boolean netWorkState) {
        MyLogUtil.e("onNetChange", getClass().getSimpleName() + " netWorkState==" + netWorkState);
        //集成BaseActivity 使用
        this.netWorkState = netWorkState;
        //不继承BaseActivity 、跨域啥时候使用
        SPStaticUtils.put(SPTools.netWorkState, netWorkState);
        if (netWorkState) {
            if (NetworkUtils.isMobileData()) {
                //移动网络 给出提示
                ToastUtils.showLong("当前网络为移动网络");
            }
            Activity topActivity = ActivityUtil.getTopActivity();
            //防止重复上传
//            if (getClass().getName().equals(topActivity.getPackageName() + "." + topActivity.getLocalClassName())) {
//                password = SPStaticUtils.getString(SPTools.password);
//                if (StringUtils.isEmpty(password)) {
//                    uploadTask();
//                } else {
//                    login();
//                }
//
//            }
        } else {
            ToastUtils.showLong(getResources().getString(R.string.text_no_net));

        }

    }

    public void setSrlEnableOverScrollDrag(boolean enable) {
        baseSrlUp.setEnableOverScrollDrag(enable);
    }

    protected void checkUpdate() {
        if (Constant.getInstance().isXUpdate) {
            XUpdate.newBuild(this)
                    .updateUrl(Constant.getInstance().GET_UPDATE)
                    .supportBackgroundUpdate(true)
                    .promptThemeColor(getResources().getColor(R.color.update_theme_Color))
                    .promptButtonTextColor(getResources().getColor(R.color.color_white))
                    .promptTopResId(R.mipmap.img_update_top)
                    .update();
//             .updatePrompter(new CustomUpdatePrompter()) //自定义版本更新提示器
        }
    }

    @Override
    public void setContentView(int layoutResID) {
        initScreenAdaption();
        super.setContentView(R.layout.activity_base);
        mRelLayoutBase = (RelativeLayout) findViewById(R.id.relLayoutBase);
        baseSrlUp = (SmartRefreshLayout) findViewById(R.id.base_srl_up);
        mFraLayoutContent = (FrameLayout) findViewById(R.id.fraLayoutContent);
        layoutTop = (LinearLayout) findViewById(R.id.layoutTop);
        statusBarView = (View) findViewById(R.id.statusBarView);
        mFraLayoutHeadView = (FrameLayout) findViewById(R.id.fraLayoutHeadView);
        LayoutInflater.from(this).inflate(titlebarResId, mFraLayoutHeadView, true);
        LayoutInflater.from(this).inflate(layoutResID, mFraLayoutContent, true);
        mLoadingBar = (ProgressBarLayout) findViewById(R.id.load_bar_layout);
        topProgressBar = (ProgressBar) findViewById(R.id.top_progress_bar);
        errorLayout = (RelativeLayout) findViewById(R.id.errorLayout);
        emptyLayout = (RelativeLayout) findViewById(R.id.emptyLayout);
        mResetButton = (TextView) findViewById(R.id.reset_button);
        mResetButton.setOnClickListener(this);

        int statusBarHeight = BarUtils.getStatusBarHeight();//单位是px

        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) statusBarView.getLayoutParams();
        layoutParams.height = statusBarHeight;
        statusBarView.setLayoutParams(layoutParams);

        //沉侵式状态栏
        ImmersionBar immersionBar = ImmersionBar.with(this);
        immersionBar.statusBarDarkFont(true);
        immersionBar.init();
    }

    /**
     * 初始化屏幕适配
     */
    protected void initScreenAdaption() {
        if (Constant.getInstance().isScreenAdaption) {
            if (ScreenUtils.isPortrait()) {
                if (ScreenUtils.isTablet()) {
                    AdaptScreenUtils.adaptWidth(BaseApplication.getBaseApplication().getResources(), AppConfig.widthInPxTable);
                } else {
                    ScreenUtils.adaptScreen4VerticalSlide(this, AppConfig.widthInPx);
                }

            } else {
                if (ScreenUtils.isTablet()) {
                    AdaptScreenUtils.adaptHeight(BaseApplication.getBaseApplication().getResources(), AppConfig.heightInPxTable);
                } else {
                    ScreenUtils.adaptScreen4HorizontalSlide(this, AppConfig.heightInPx);
                }
            }
        }
    }


    protected void onClickedTopLeftButtton(View view) {
        ActivityUtil.getInstance().removeActivity(this);
    }

    protected void onClickFailureResetButton(View view) {
    }

    protected void onClickTitlebarShare(View view) {
    }

    protected void onClickTitlebarRight(View view) {
    }

    protected void onClickTitlebarRightText(View view) {
    }

    protected void initMap(Bundle savedInstanceState) {
        //同意隐私状态,需要在初始化地图之前完成
//        MapsInitializer.updatePrivacyShow(context, true, true);
//        MapsInitializer.updatePrivacyAgree(context, true);
    }

    protected void onKeyDownEvnet() {

    }

    /**
     * 获取布局ID
     */
    protected abstract int getLayoutId();

    /**
     * 初始化视图
     */
    protected abstract void initView();

    /**
     * 数据初始化操作
     */
    protected abstract void initData();

    /**
     * 请求数据
     */
    protected abstract void getData();


    /**
     * 权限检查方法，false代表没有该权限，ture代表有该权限
     */
    public boolean hasPermission(String... permissions) {
        for (String permission : permissions) {
            if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
                return false;
            }
        }
        return true;
    }


    /**
     * 权限请求方法
     */
    public void requestPermission(int code, String... permissions) {
        ActivityCompat.requestPermissions(this, permissions, code);
    }

    /**
     * 处理请求权限结果事件
     *
     * @param requestCode  请求码
     * @param permissions  权限组
     * @param grantResults 结果集
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        doRequestPermissionsResult(requestCode, grantResults);
    }

    /**
     * 处理请求权限结果事件
     *
     * @param requestCode  请求码
     * @param grantResults 结果集
     */
    public void doRequestPermissionsResult(int requestCode, @NonNull int[] grantResults) {
    }


    /**
     * 解除网络状态监听
     */
    public void unregisterReceiver() {
        unregisterReceiver(networkChangeReceiver);
//        netEvent = null; //防止造成内存泄漏
    }

    /**
     * 功能：如果自定义headview,一定要在setContentView前调用,否则无效
     *
     * @param layoutResID
     * @author:
     */
    protected void setHeadView(int layoutResID) {
        this.titlebarResId = layoutResID;
    }

    //隐藏头部
    protected void hideHeadView() {
        layoutTop.setVisibility(View.GONE);
    }

    //显示头部
    protected void showHeadView() {
        layoutTop.setVisibility(View.VISIBLE);
    }

    //显示加载布局
    protected void showLoadingBar() {
        showLoadingBar(false);
    }

    //隐藏加载布局
    public void hideLoadingBar() {
        mLoadingBar.hide();
    }

    public void showLoadingBar(boolean transparent) {
        mLoadingBar.setBackgroundColor(transparent ? Color.TRANSPARENT : getResources().getColor(R.color.main_bg));
        mLoadingBar.show();
    }

    //隐藏顶部的进度条
    public void hideTopProgressBar() {
        topProgressBar.setVisibility(View.GONE);
    }

    //隐藏顶部的进度条
    public void showTopProgressBar() {
        topProgressBar.setVisibility(View.VISIBLE);
    }

    //加载布局是否显示
    public boolean isLoadingBarShow() {
        return mLoadingBar.getVisibility() == View.VISIBLE;
    }

    //显示无网络布局
    protected void showErrorLayout() {
        errorLayout.setVisibility(View.VISIBLE);
    }

    //隐藏无网络布局
    protected void hideErrorLayout() {
        errorLayout.setVisibility(View.GONE);
    }

    //显示空页面
    public void showEmptyLayout(String emptyHit) {
        emptyLayout.setVisibility(View.VISIBLE);
        if (tvEmtyHit == null) {
            tvEmtyHit = (TextView) findViewById(R.id.tvEmtyHit);
        }
        tvEmtyHit.setText(emptyHit);
    }

    //隐藏空页面
    public void hideEmptyLayout() {
        emptyLayout.setVisibility(View.GONE);
    }

    protected RelativeLayout getErrorLayout() {
        return errorLayout;
    }


    //设置头部文字颜色
    protected void setModuleTitleColor(int resourceId) {
        if (moduleTextView == null) {
            moduleTextView = (TextView) findViewById(R.id.tvTitlebarTitle);
        }
        moduleTextView.setTextColor(getResources().getColor(resourceId));
    }

    //设置头部局部
    protected void setModuleTitle(int resourceId) {
        if (moduleTextView == null) {
            moduleTextView = (TextView) findViewById(R.id.tvTitlebarTitle);
        }
        moduleTextView.setText(resourceId);
    }

    //设置头部文字
    protected void setModuleTitle(String text) {
        if (moduleTextView == null) {
            moduleTextView = (TextView) findViewById(R.id.tvTitlebarTitle);
        }
        moduleTextView.setVisibility(View.VISIBLE);
        moduleTextView.setText(text);
    }

    //设置头部文字
    protected void setModuleTitleSize(int dp) {
        if (moduleTextView == null) {
            moduleTextView = (TextView) findViewById(R.id.tvTitlebarTitle);
        }
        moduleTextView.setVisibility(View.VISIBLE);
        moduleTextView.setTextSize(SizeUtils.dp2px(dp));
    }

    //设置右侧文字大小
    protected void setRightTextSize(int size) {
        rightText.setTextSize(size);
    }

    //设置右侧文字大小
    protected void setRightTextColor(int color) {
        rightText.setTextColor(color);
    }

    //设置右侧文字
    protected void setRightText(String str) {
        if (rightText == null) {
            rightText = findViewById(R.id.tv_right_text);
            rightText.setOnClickListener(this);
        }
        rightText.setVisibility(View.VISIBLE);
        rightText.setText(str);
    }

    //显示右侧文字
    protected void showRightText() {
        if (rightText == null) {
            rightText = findViewById(R.id.tv_right_text);
            rightText.setOnClickListener(this);
        }
        rightText.setVisibility(View.VISIBLE);
    }

    //隐藏右侧文字
    protected void hideRightText() {
        if (rightText == null) {
            rightText = findViewById(R.id.tv_right_text);
        }
        rightText.setVisibility(View.GONE);
    }

    //设置头部图片
    protected void setModuleTitleImg(int resId) {
        if (moduleTextView == null) {
            moduleTextView = (TextView) findViewById(R.id.tvTitlebarTitle);
        }
        moduleTextView.setVisibility(View.VISIBLE);
        moduleTextView.setText("");
        moduleTextView.setCompoundDrawablesWithIntrinsicBounds(resId, 0, 0, 0);
    }

    //隐藏头部文字
    protected void hideModuleTitle() {
        if (moduleTextView == null) {
            moduleTextView = (TextView) findViewById(R.id.tvTitlebarTitle);
        }
        moduleTextView.setVisibility(View.GONE);
    }

    //隐藏左上
    protected void hideTopLeftButton() {
        if (topLeftButton == null) {
            topLeftButton = (ImageView) findViewById(R.id.ivTitlebarLeft);
        }
        topLeftButton.setVisibility(View.INVISIBLE);
    }


    protected void showTopLeftButton() {
        if (topLeftButton == null) {
            topLeftButton = (ImageView) findViewById(R.id.ivTitlebarLeft);
            topLeftButton.setOnClickListener(this);
        }
        topLeftButton.setVisibility(View.VISIBLE);
    }

    protected void setTopLeftButton(int img) {
        topLeftButton.setImageResource(img);
    }

    protected void showTopRightShare() {
        if (topRightShare == null) {
            topRightShare = (ImageView) findViewById(R.id.ivTitlebarShare);
            topRightShare.setOnClickListener(this);
        }
        topRightShare.setVisibility(View.VISIBLE);
    }

    protected RelativeLayout getlayoutBase() {
        return mRelLayoutBase;
    }

    protected View getHeadView() {
        return mFraLayoutHeadView;
    }

    protected ImageView getTopLeftButton() {
        if (topLeftButton == null) {
            topLeftButton = (ImageView) findViewById(R.id.ivTitlebarLeft);
        }
        return topLeftButton;
    }


    //显示右上图片，只有图片 不含文字
    protected void showTopRightImg(int img) {
        if (topRightImg == null) {
            topRightImg = (ImageView) findViewById(R.id.ivTitlebarRight);
            topRightImg.setOnClickListener(this);
        }
        topRightImg.setVisibility(View.VISIBLE);
        topRightImg.setImageResource(img);
    }

    //隐藏右上图片，只有图片 不含文字
    protected void hideTopRightImg() {
        if (topRightImg == null) {
            topRightImg = (ImageView) findViewById(R.id.ivTitlebarRight);
        }
        topRightImg.setVisibility(View.INVISIBLE);
    }

    protected void showLoadingDialogCancle() {
        if (mProgressDialogCancle == null) {
            mProgressDialogCancle = DialogUtils.createProgressDiaolg(this, "加载中...", true);
        }
        if (!mProgressDialogCancle.isShowing()) {
            mProgressDialogCancle.show();
        }
    }

    protected void hideLoadingDialogCancle() {
        if (mProgressDialogCancle == null) {
            mProgressDialogCancle = DialogUtils.createProgressDiaolg(this, "加载中...", true);
        }
        if (mProgressDialogCancle.isShowing()) {
            mProgressDialogCancle.dismiss();
        }
    }

    protected void showLoadingDialog() {
        if (mProgressDialog == null) {
            mProgressDialog = DialogUtils.createProgressDiaolg(this, "加载中...", false);
        }
        if (!mProgressDialog.isShowing()) {
            mProgressDialog.show();
        }
    }

    protected void hideLoadingDialog() {
        if (mProgressDialog == null) {
            mProgressDialog = DialogUtils.createProgressDiaolg(this, "加载中...", false);
        }
        if (mProgressDialog.isShowing()) {
            mProgressDialog.dismiss();
        }
    }


    protected void showLoadingDialog(String title) {
        if (mProgressDialog == null) {
            mProgressDialog = DialogUtils.createProgressDiaolg(this, title, false);
        }
        if (!mProgressDialog.isShowing()) {
            mProgressDialog.show();
        }
    }

    protected void hideLoadingDialog(String title) {
        if (mProgressDialog == null) {
            mProgressDialog = DialogUtils.createProgressDiaolg(this, title, false);
        }
        if (mProgressDialog.isShowing()) {
            mProgressDialog.dismiss();
        }
    }

    /**
     * 下载加载dialog
     */
    protected void showDownLoadDialog() {
        try {
            if (!isFinishing()) {
                if (mLoadingDialog == null) {
                    mLoadingDialog = new LoadingDialog(this, "下载中...");
                }
                if (mLoadingDialog.isShowing()) {
                    mLoadingDialog.dismiss();
                }
                mLoadingDialog.show();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 取消下载加载dialog
     */
    protected void hideDownLoadDialog() {
        if (!isFinishing()) {
            try {
                if (mLoadingDialog != null
                        && mLoadingDialog.isShowing()) {
                    mLoadingDialog.dismiss();
                }
            } catch (Exception e) {
                mLoadingDialog = null;
                e.printStackTrace();
            }
        }
    }

    //标题栏背景色
    protected void setTitleBarBackground(Drawable drawable) {
        if (clTitlebar == null) {
            clTitlebar = (LinearLayout) findViewById(R.id.clTitlebar);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                //Android系统大于等于API16，使用setBackground
                clTitlebar.setBackground(drawable);
            } else {
                //Android系统小于API16，使用setBackgroundDrawable
                clTitlebar.setBackgroundDrawable(drawable);
            }
        }

    }

    protected void setTitleBarBackground(int color) {
        if (clTitlebar == null) {
            clTitlebar = (LinearLayout) findViewById(R.id.clTitlebar);
            clTitlebar.setBackgroundColor(color);
        }

    }


    //状态栏背景色
    protected void setStatusBarBackground(Drawable drawable) {


        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            //Android系统大于等于API16，使用setBackground
            statusBarView.setBackground(drawable);
        } else {
            //Android系统小于API16，使用setBackgroundDrawable
            statusBarView.setBackgroundDrawable(drawable);
        }


    }

    protected void setStatusBarBackground(int color) {
        statusBarView.setBackgroundColor(color);
    }

    public View getmFraLayoutContent() {
        return mFraLayoutContent;
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.ivTitlebarLeft) {
            onClickedTopLeftButtton(v);
        } else if (i == R.id.ivTitlebarShare) {
            onClickTitlebarShare(v);
        } else if (i == R.id.ivTitlebarRight) {
            onClickTitlebarRight(v);
        } else if (i == R.id.reset_button) {
            onClickFailureResetButton(v);

        } else if (i == R.id.tv_right_text) {
            onClickTitlebarRightText(v);
        }
    }

    public void showLogoutDialog(Handler handler) {
        myDialog = new MyDialog(this);
        myDialog.setOnSureClickListener(new MyDialog.OnSureClickListener() {
            @Override
            public void onSureClick() {
                myDialog.dismiss();
                handler.removeCallbacksAndMessages(null); //清空消息队列&结束Handler生命周期
                IntentUtils.getInstance().readyGo(ActivityUtil.getTopActivity(), LoginActivity.class);
                ActivityUtil.removeAllActivity();
            }
        });
        myDialog.show();
    }

    public MyDialog getLogoutDialog() {
        return myDialog;
    }


}
